﻿using QianJiaInfo.Models;
using System;
using System.Linq;
using System.Threading.Tasks;

namespace QianJiaInfo.Service
{
    public class AddressService : IManageServices<Address>
    {

        public async Task<bool> AddAsync(Address Context)
        {
            using (var context = new ResidenceContext())

            {
                context.Addresses.Add(Context);

                return await context.SaveChangesAsync() == 1 ? true : false;

            }

        }

        public async Task<bool> DeleteAsync(Address Context)
        {
            using (var dbcontext = new ResidenceContext())
            {
                var address = dbcontext.Addresses.Single(a => a.AddressId == Context.AddressId);
                address.Effective = false;
                return await dbcontext.SaveChangesAsync() == 1 ? true : false;

            }
        }

        public Task<IQueryable<Address>> QueryAsync(Address Context)
        {
            throw new NotImplementedException();
        }

        public Task<Address> UpdateAsync(Address Context)
        {
            throw new NotImplementedException();
        }
    }
}
